<?php

    include_once("config.php");

    ob_start();
    include_once(INCLUDE_DIR. "/Partner.php");
    ob_clean();

    $order = !empty($_REQUEST["order"]) ? $_REQUEST["order"] : "add_time desc";
    $page = !empty($_REQUEST["page"]) ? $_REQUEST["page"] : 1;
    $page_size = !empty($_REQUEST["page_size"]) ? $_REQUEST["page_size"] : 10;

    $myMySQL = new MySQL();
    $myMySQL->connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
   
    $myPartner = new Partner($myMySQL);

    $total_count = $myPartner->getCount($condition);
    $total_page = $myPartner->getPageCount($page_size, $condition);

    $total_page = ($total_page == 0) ? 1 : $total_page;
    $page = ($total_page < $page) ? $total_page : $page;

    // list
    $condition = "1=1";
    $rows = $myPartner->getPage("*", $page, $page_size, $condition ." ORDER BY ". str_replace("-", " ", $order));

    $result = array();
    $result['total_page']  = $total_page;
    $result['total_count'] = $total_count;
    $result['page']        = $page;
    $result['page_size']   = $page_size;

    for($i = 0; isset($rows[$i]); $i++)
    {   
        $dataArray = $myPartner->getDataClean($rows[$i]);

        $result['data'][] = $dataArray;
    }

    Output::succ('', $result);

?>